package com.glacier.common.core.domain;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * date 2022-10-26 12:26
 * 树型实体
 *
 * @author glacier
 * @version 1.0
 */
public abstract class TreeEntity<T extends TreeEntity<T>> extends BaseEntity implements Treeable<T> {

	private static final long serialVersionUID = 4832790932661896292L;
	/**
	 * 名称
	 */
	protected String title;

	/**
	 * 父级主键
	 */
	protected String parentId = "";

	/**
	 * 排序
	 */
	protected int sort;

	/**
	 * 子类
	 */
	protected List<T> children;

	/**
	 * 父级名称
	 */
	protected String parentTitle;

	/**
	 * 多选
	 */
	private String checkArr = "0";


	protected TreeEntity() {
	}

	protected TreeEntity(String id) {
		super(id);
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Override
	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	@Override
	public int getSort() {
		return sort;
	}

	public void setSort(int sort) {
		this.sort = sort;
	}

	@Override
	public List<T> getChildren() {
		return Optional.ofNullable(children)
				.orElseGet(() -> children = new ArrayList<>(8));
	}

	@Override
	public void setChildren(List<T> children) {
		this.children = children;
	}

	public String getParentTitle() {
		return parentTitle;
	}

	public void setParentTitle(String parentTitle) {
		this.parentTitle = parentTitle;
	}

	public String getCheckArr() {
		return checkArr;
	}

	public void setCheckArr(String checkArr) {
		this.checkArr = checkArr;
	}

	@Override
	public String toString() {
		return "TreeEntity{" +
				", title='" + title + '\'' +
				", parentId='" + parentId + '\'' +
				", sort=" + sort +
				", children=" + children +
				", createBy='" + createBy + '\'' +
				", createTime=" + createTime +
				", updateBy='" + updateBy + '\'' +
				", updateTime=" + updateTime +
				", remark='" + remark + '\'' +
				", id='" + id + '\'' +
				'}';
	}
}
